﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using sipfe.util;

using sipfe.service.mante;

namespace sipfe.Controllers.Base
{
    public class BaseSipfeController : Controller
    {

        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {        
            
            if (filterContext.HttpContext.Session != null && !HttpContext.Request.IsAjaxRequest())
            {
                if (filterContext.HttpContext.Session[Constante.V_COD_USUARIO] == null)
                {
                    filterContext.Result = RedirectToAction("Index", "../Seguridad");
                }
            }
            base.OnActionExecuting(filterContext);
        }

        protected void setPaginacion(IList<dynamic> lista, string strNumeroRegMostrar,double NumTotalRegistros)
        {
            double dNumRegMostrarXPag = 0D;
            double dNumTotalDePaginas = 0D;

            if (string.IsNullOrEmpty(strNumeroRegMostrar))
            {
                dNumRegMostrarXPag = Constante.NUM_REGISTROS_SHOW;
            }
            else
            {
                dNumRegMostrarXPag = Convert.ToDouble(strNumeroRegMostrar);
            }
            dNumTotalDePaginas = Math.Ceiling(NumTotalRegistros / dNumRegMostrarXPag);
            ViewBag.NUM_REG_MOSTRAR     =   dNumRegMostrarXPag;
            ViewBag.NUM_TOTAL_PAGINAS   =   dNumTotalDePaginas;
            ViewBag.NUM_TOTAL_REG       =   NumTotalRegistros;            
        }

        
        protected SelectList formaSelectCompendio(int id)
        {
           return new SelectList(CacheCompendio.getInstance().getListCompendioById(id), "nIdeDetalle", "vNomCorto");
        }

        protected SelectList formaSelectCompendioLargo(int id)
        {
            return new SelectList(CacheCompendio.getInstance().getListCompendioById(id), "nIdeDetalle", "vNomDetalle");
        }

        protected SelectList formaSelectTipoDep(int id)
        {   
            return new SelectList(CacheCompendio.getInstance().getListRegiones(id), "nIdeDep", "vDescRegion");
        }
        protected SelectList formaSelectProvincias(int id)
        {
            return new SelectList(CacheCompendio.getInstance().getListCompendioGrupoById(id), "nIdeDetalle", "vNomCorto");
        }
        protected SelectList formaSelectGrupos(int id)
        {
            return new SelectList(CacheCompendio.getInstance().getListCompendioGrupoById(id), "nIdeDetalle", "vNomCorto");
        }
        protected SelectList formaSelectGruposDetalle(int id)
        {
            return new SelectList(CacheCompendio.getInstance().getListCompendioGrupoById(id), "nIdeDetalle", "vNomDetalle");
        }
        protected SelectList formaSelectDistritos(int id)
        {
            return new SelectList(CacheCompendio.getInstance().getListRegiones(id), "nIdeDetalle", "vNomCorto");
        }

        protected SelectList formaSelectBandejaUser(string id,string nIdeDep)
        {
            return new SelectList(CacheCompendio.getInstance().getListBandejaUsuario(id), "nIdeItem", "vDescrItem",nIdeDep);
        }

        protected SelectList formaSelectEmpresaPabe(int nVinculo)
        {
            return new SelectList(CacheCompendio.getInstance().getListEmpresaPabe(nVinculo), "nIdeEmpresa", "vRazonSocial");
        }

       
        protected string getPathMante()
        {//exportor.TemplateFileName = miCarpeta + "Views\\Estadistica\\Template" + tipo + ".xlsx";

            return Server.UrlPathEncode("~/") + "Views\\mante\\";
        }

        protected List<SelectListItem> formaSelectVacio()
        {
                List<SelectListItem> items = new List<SelectListItem>();
                items.Add(new SelectListItem() {Text = "--Seleccionar--", Value = "" });
                return items;
        }
        protected string _pagina = "general/SinRegistros";
        protected string _titulo = "";

        protected void _cargaPaisTipoDoc()
        {
            ViewBag.PaisEmisor = formaSelectCompendio(Constante.getInstance().N_IDE_TABLA_PAIS_EMISOR);
            ViewBag.TipoDocIdent = formaSelectCompendio(Constante.getInstance().N_IDE_TABLA_TIPO_DOC_IDENTIFICACION);
        }

        
            


        

    }
}
